﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Threading;
using System.Diagnostics;



namespace Net
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            //bool bCreatedNew;
            //Mutex m = new Mutex(false, "swu-netTool", out bCreatedNew);
            //if (bCreatedNew)
            //    Application.Run(new MainForm());

            //string info = "swu-netTool";
            //Mutex mutex = new Mutex(false,info);

            //   //判断互斥体是否使用中。
            //   bool RunExists = !mutex.WaitOne(0, false);
            //   if (! RunExists )
            //       Application.Run(new MainForm());
            //   else
            //       MessageBox.Show("应用程序已经启动！感谢您的使用！");


            //Application.EnableVisualStyles();
            //Application.SetCompatibleTextRenderingDefault(false);

            int ProceedingCount = 0;
            Process[] ProceddingCon = Process.GetProcesses();
            foreach (Process IsProcedding in ProceddingCon)
            {
                if (IsProcedding.ProcessName == Process.GetCurrentProcess().ProcessName)
                {
                    ProceedingCount += 1;
                }
            }
            if (ProceedingCount > 1)
            {
                MessageBox.Show("程序已经在运行中，感谢您的使用！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
            else
            {
                Application.EnableVisualStyles();
                Application.DoEvents();
                MainForm mainform = new MainForm();
                mainform.StartPosition =  FormStartPosition.CenterScreen;
                Application.Run(mainform);
            }

           
        }

        //private static bool CheckInstance()
        //{
        //    string procName = System.Diagnostics.Process.GetCurrentProcess().ProcessName;
        //    if ((System.Diagnostics.Process.GetProcessesByName(procName)).GetUpperBound(0) > 0)
        //    {
        //        return true;
        //    }
        //    else
        //    {
        //        return false;
        //    }
        //}

    }
}
